import requests
import json
from django.http import JsonResponse


# APPID = '98529'
APPID = '107284'
# APPKEY = '7937df459e9b4e50001b404af35b1e0d'
APPKEY = 'b52866d169c63c15cd6af0a8b719778a'
URL = 'https://api-v4.mysubmail.com/sms/xsend.json'


def send_sms(kind, phone, vars):
    # KIND
    # 需要审核
    if kind == 1:
        # project = 'MpPB23'
        project = 'FJgCM'
    # 车辆入场通知
    elif kind == 2:
        # project = 'RzmPH1'
        project = '2ermB'
    header = {"Content-type": "application/json"}
    param = {
        'appid': APPID,
        'signature': APPKEY,
        'project': project,
        'to': phone,
        'vars': json.dumps(vars)
    }
    res = requests.post(URL, data=json.dumps(param), headers=header)
    print(res.json())
    return JsonResponse(dict(code=0, msg="OK"))